var tests = ["test_contactmgr_testQueryForCity"];

var setup = function() {
    var preTestCount = root.addresses.countries.count();

    var country = new Country("XXX", "Testcountry");
    root.addresses.countries.add(country);

    var city1    = new City("12345", "Testcity 1");
    country.cities.add(city1);

    var city2    = new City("12340", "Testcity 2");
    country.cities.add(city2);

    res.commit();
}

var test_contactmgr_testQueryForCity = function() {
    var cities = root.addresses.citiesForCountry("XXX", "123");
    assertEqual(2, cities.count());
    cities.forEach(function(i) {
        var city = cities.get(i);
        assertEqual(true, (city.zip == "12345" || city.zip == "12340"));
        assertEqual(true, (city.name == "Testcity 1" || city.name == "Testcity 2"));
    });

    cities = root.addresses.citiesForCountry("XXX", "Testcity");
    assertEqual(2, cities.count());
    cities.forEach(function(i) {
        var city = cities.get(i);
        assertEqual(true, (city.zip == "12345" || city.zip == "12340"));
        assertEqual(true, (city.name == "Testcity 1" || city.name == "Testcity 2"));
    });

    cities = root.addresses.citiesForCountry("XXX", "Testcity 1");
    assertEqual(1, cities.count());
    var city = cities.get(0);
    assertEqual("12345", city.zip);
    assertEqual("Testcity 1", city.name);    
};

var cleanup = function() {
    var country = root.addresses.countries.get("XXX");
    root.addresses.countries.removeChild(country);
    country.cities.forEach(function(i) {
       country.cities.get(i).remove(); 
    });
    country.remove();

    res.commit();
};